package com.demo;

import com.alibaba.fastjson.JSONObject;

import java.math.BigDecimal;

/**
 * @author gy
 * @date 2022/5/27
 */
public class JsonParseJavaObject {

    public static void main(String[] args) {
//        {
//            "amount": -8,
//                "type": 0,
//                "userId": "432442",
//                "goodsNums": [
//            {
//                "money": 8,
//                    "goodsId": 259,
//                    "num": 1
//            }
//    ]
//        }
        JSONObject jo = new JSONObject();
        jo.put("amount",-8);
        jo.put("type",0);
        jo.put("userId","432442");
        GoodsNum goodsNum = new GoodsNum();
        goodsNum.setMoney(new BigDecimal(8));
        goodsNum.setGoodsId(259);
        goodsNum.setNum(1);
        jo.put("goodsNums", goodsNum);

        // JSONObject.toJavaObject  json 对象转化为  javabean
        DeductOrRefundMoneyReq deductOrRefundMoneyReq = JSONObject.toJavaObject(jo, DeductOrRefundMoneyReq.class);
        System.out.println(deductOrRefundMoneyReq.toString());

    }
}
